﻿var pagecount = "0";
var num = 0;
var page = 1;
var keyword = ""; //关键词
var hannelid = ""; //频道id
var authid = "1"; //作者id
var hid = "";
var itemCount = 0;
var source = 0;
$(document).ready(function () {
    source = getQueryString("source");
    load(page);
    $(window).bind("scroll", function () {
        //当滚动条滚动时
        var scollTop = $(this).scrollTop() + $(this).height();
        var scollH = $(document).height();

        if (scollH - scollTop < 100) {
            if (wait.isShow) { return; } //如果正在加载，则返回  
            page++;
            load(page);

        }
        return false;
    });

    $(".topleft").bind("click", function () {
        if (source == 1)
            window.location.href = 'articleadd.html' //发布
        else
            window.location.href = 'Makead_3.html'  //发财
    });
});

function load(page) {
    if (pagecount == "1") { return; }
    if (!islogin()) { window.location.href = 'login.html'; return; }
    ajax.GetSharelist("is_other=0&page_index=" + page, function (data) {
        if (data.code != 0) {
            Alert(data.msg);
            pagecount = "1";
            return;
        }
        if (data.item.pageCount < page) {
            if (pagecount == "0")
                Alert('到底了！');
            pagecount = "1"; return;
        }

        $(data.item.table).each(function () {
            num++;
            var logoimg = this.article_logo == null ? "img/30.png" : this.article_logo;
            var titles;
            if (this.type == 1)
                titles = this.article_title;
            else if (this.type == 2) {
                titles = this.url_title;
                if (this.url_logo != null && this.url_logo != "")
                    logoimg = this.url_logo;
            }
            if (titles == null) titles = "";
            if (titles.length > 12)
                titles = titles.substr(0, 12) + "...";
            $(".tg_select").append("<div class=\"centenlist\"><div class=\" centenimg\"><img src=\"" + logoimg + "\"  /></div><div class=\"cententxt\" onclick=\"Select('" + this.id + "','" + this.advert_id + "')\" ><div class=\"cententxttop\"><strong>" + titles + "</strong></div><div class=\"centenTime\">" + this.date.substr(0, 10) + " </div></div>" +
            "<div id='id" + this.id + "' style='display:none'>" + (this.article_id == null ? "" : this.article_id) + "</div>" +
            "<div id='title" + this.id + "' style='display:none'>" + (this.url_title == null ? "" : this.url_title) + "</div>" +
            "<div id='logo" + this.id + "' style='display:none'>" + (this.url_logo == null ? "" : this.url_logo) + "</div>" +
            "<div id='url" + this.id + "' style='display:none'>" + (this.url == null ? "" : this.url) + "</div>" +
           "</div>");
        });
        loadhtml();
    });
}

function loadhtml() {
    $(".centenflow").click(function () {
        $(this).css("color", "#F37B0B");
        window.location.href = "Statistical.html?Shareid=" + $(this).attr("name") + "&type=Share";
        return false;
    });
}

function Select(id,advertid) {
    var article_id = encodeURIComponent($("#id" + id).html());
    //发布频道
    if (source == 1) {
        window.location.href = "detail.aspx?is_app=1&shareid=" + id + "&article_id=" + article_id;
    }
    else {
        //发财频道
        if (!confirm("选中此条作为广告文章吗?")) return false;
        var title = encodeURIComponent($("#title" + id).html());
        var logo = encodeURIComponent($("#logo" + id).html());
        var url = encodeURIComponent($("#url" + id).html()); 
        url = encodeURIComponent(wjx_domain + "/client/item_new.aspx?article_id=" + article_id + "&advert_id=" + advertid + "&shareid=" + id);
        var param = "article_id=" + article_id + "&url_title=" + title + "&url_logo=" + logo + "&url=" + url;
        AjaxStart("ajax/fc_article.ashx?add", param, function (data) {
            if (data.code == 0) {
                Alert("添加成功，请完善设置");
                setTimeout(function () { window.location.href = 'makeset.html?id=' + data.item }, 1000);
            }
            else
                Alert(data.msg);
        });
    }
}